home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Novice programmer needs help!
- Date: Sun, 17 Mar 96 17:36:34 GMT
- Organization: none
- Message-ID: <827084194snz@genesis.demon.co.uk>
- References: <4ieov7$r5@lantana.singnet.com.sg> <314AB830.684@uthscsa.edu>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <314AB830.684@uthscsa.edu> Monzon@uthscsa.edu "Merardo Monzon" writes:
-
- >Novice Porgrammer, I compiled the application you've provided after
- >fixing about 5-7 errors. I don't know what compiler you are using my
- >Mac Symantec C++ compiler compiled the program after I fixed the
- >following errors:
-
- The original poster said he was learning C and posted to comp.lang.c so why
- on earth are you trying to validate his code with a C++ compiler?
-
- >
- > 1) #define totnum 20 //total no. of entries in list=20
- >
- >
- > //total no. of entries in list=20
- > Fixed: #define totnum 20
- >
- > 2) struct list *friend[numtot];
- >
- > Fixed: struct list *friend[totnum];
- > // NOT numtoto but totnum
- >
- > 3) fgets(friend[num]->name[],15,stdin); // Syntax ERROR
- >
- > Fixed: fgets(friend[num]->name,15,
- >stdin);
- >
- >Error number 3 occurrs multiple time in your code.
- >
- >Error number 1 is very common for novice C programmers to make. The
- >totnum macro will be replaced with everything to the right of the
- >white space, (i.e. 20 //total no. of entries in list=20). Look at
- >the source listing to see how tonum is replaced with the macro
- >you've defined.
-
- Since we are talking about C code here the only thing to be said is that
- // is illegal (it is a syntax error). The only syntax the C language provides
- for comments is /* */ . If you set your compiler to an ANSI C conformant mode
- it must complain about //, other than within /* */ comments, string literals
- (wide character constants?) or part of //* as in:
-
- a = b //**/ 5;
-
- Note that is this a legal C statement any C compiler must compile it as
-
- a = b / 5;
-
- (launches off-topic)
-
- In C++ (as well as C) comments are converted to a white-space character
- before macro substitution is performed. So if your C++ compiler compiles:
-
- #define totnum 20 //total no. of entries in list=20
-
- with different effect to:
-
- //total no. of entries in list=20
- #define totnum 20
-
- it is severely broken.
-
- (splash-down)
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-